<template>
  <div>
    <div class="no-content" v-if="Exam !== 1">暂时没有抵扣券</div>
    <div class="rebate_box" v-else>
      <el-row :gutter="10" class="rebate_head_box">
        <el-col :span="8" >
          <div class="rebate_cell">
            <div class="rebate_icon back_money">
              <i class="iconfont el-icon-knife-handout icon_font_size"></i>
            </div>
            <div class="rebate_text">
              <span class="title_ora">￥{{rebateObj.rebateAmount}}</span>
              <p>返利金</p>
            </div>
          </div>
        </el-col>
        <el-col :span="8" >
          <div class="rebate_cell">
            <div class="rebate_icon income_money">
              <i class="iconfont el-icon-knife-money icon_font_size"></i>
            </div>
            <div class="rebate_text">
              <span>￥{{rebateObj.addAmount}}</span>
              <p>总收入</p>
            </div>
          </div>
        </el-col>
        <el-col :span="8" >
          <div class="rebate_cell">
            <div class="rebate_icon expand_money">
              <i class="iconfont el-icon-knife-youhui icon_font_size"></i>
            </div>
            <div class="rebate_text">
              <span>￥{{rebateObj.payAmount}}</span>
              <p>总支出</p>
            </div>
          </div>
        </el-col>
      </el-row>
      <!-- table -->
      <div class="rebate_table">
        <h2 class="content_title">返利金交易明细</h2>
        <el-table :data="rebateList" style="width: 100%" header-row-class-name="table_thead_style">
          <el-table-column
            label="时间"
            prop="createTime">
          </el-table-column>
          <el-table-column label="交易金额">
            <template slot-scope="props">
            {{props.row.type === 1 ? '+' : '-'}}{{props.row.amount}}
            </template>
          </el-table-column>
          <el-table-column
            label="订单编号"
            prop="orderId">
          </el-table-column>
          <el-table-column
            label="类别">
            <template slot-scope="props">
              {{rebateType[props.row.type]}}
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="props">
              <router-link :to="{name: 'orderDetail', params: {orderId: props.row.orderId}}">查看详情</router-link>
              <!-- <el-button type="text">查看详情 {{props.row.orderId}}</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <!-- pagination -->
        <el-row v-if="page && page.totalPages > 1">
          <el-pagination background layout="total, prev, pager, next, ->" :total="page.totalRecords" :page-size="page.pageSize" @current-change="handlePage"  class="page_box"></el-pagination>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script>
  import {Pagination, Table, TableColumn, Button, Row, Col} from 'element-ui'
  import {getRebateGold, getRebateSum} from '@/service/get-data'
  import {rebateType} from '@/tool/index'
  import {getCookie} from '@/config/mUntils'
  export default{
    components: {
      elPagination: Pagination,
      elTable: Table,
      elTableColumn: TableColumn,
      elButton: Button,
      elRow: Row,
      elCol: Col
    },
    data () {
      return {
        curpage: 1, // params 当前页
        pageNum: 10, // params 一页的数据量
        rebateObj: {}, // 返利金交易信息
        rebateList: [], // 返利金列表
        page: {} // 分页信息
      }
    },
    methods: {
      async fetchRebateObj () {
        let res = await getRebateGold(this.curpage, this.pageNum)
        res = res.data
        if (res.resultCode && res.resultCode === 2000) {
          this.rebateList = res.data.rebateList
          this.page = res.data.page
        } else {
          this.$message({
            message: res.resultMsg,
            type: 'wraming'
          })
        }
      },
      async fetchRebateSum () {
        let res = await getRebateSum()
        if (res.data.resultCode && res.data.resultCode === 2000) {
          res = res.data
          this.rebateObj = res.data
        }
      },
      // 分页
      handlePage (page) {
        this.page = page
        this.fetchRebateObj()
      }
    },
    computed: {
      rebateType () {
        return rebateType
      },
      Exam () {
        return getCookie('Exam') - 0
      }
    },
    mounted () {
      if (this.Exam !== 1) return
      this.fetchRebateObj()
      this.fetchRebateSum()
    }
  }
</script>
<style lang="scss" scoped>
  .content_title{
    font-family: PingFangSC-Medium, Microsoft YaHei;
    margin-bottom: 16px;
    font-size: 18px;
    color: #333333;
    line-height: 25px;
  }
  .rebate_box{
    position: relative;
    background:#F8F8F8;
    margin: -26px -52px;
    // padding: 25px;
  }
  .rebate_head_box{
    margin-bottom: 10px;
  }
  .rebate_cell{
    display: flex;
    justify-content: flex-start;
    background: #ffffff;
    padding: 45px 0 40px 40px;
    border-radius: 2px;
    .rebate_icon{
      margin-top:5px;
      width: 60px;
      height: 60px;
      line-height: 60px;
      border-radius: 50%;
      text-align: center;
      font-size: 30px;
      color: #ffffff;
    }
    .back_money{
      background: #FF7306;
    }
    .income_money{
      background: #26A0F5;
    }
    .expand_money{
      background: #9B9D98;
    }
  }
  .rebate_text{
    padding-left: 10px;
    color: #666666;
    .title_ora{
      color: #F55923;
    }
    span{
      font-size: 32px;
      line-height: 45px;
    }
    p{
      font-size: 18px;
      color: #999999;
      padding-left: 5px;
      line-height: 25px;
    }
  }
  .rebate_table{
    padding: 27px 52px;
    background: #ffffff;
  }
  .icon_font_size{
    font-size: 32px;
  }
</style>

